package rocky.freemanagementsystemserver.controller

import rocky.freemanagementsystemserver.Entity.User
import rocky.freemanagementsystemserver.service.interfaces.IUserService
import rocky.freemanagementsystemserver.utils.Slf4j
import rocky.freemanagementsystemserver.utils.Slf4j.Companion.log
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/user")
@Slf4j
class UserController {

    @Autowired
    lateinit var userService: IUserService

    @RequestMapping(value=[""],method = [RequestMethod.POST])
    fun addUser(@RequestBody user: User): String {
        userService.addUser(user)
        return "success"
    }
    @RequestMapping(value = ["/{id}"], method = [RequestMethod.DELETE])
    fun deleteUser(@PathVariable("id") id: String): String {
        userService.deleteUser(id)
        return "success"
    }

    @RequestMapping("list")
    fun getList(): List<User> {
        log.info("get user")
        return userService.getUsers()
    }
}